package com.liu.controller;

import com.liu.domain.R;
import com.liu.domain.TableDataInfo;
import com.liu.domain.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 *  @Api 注解用于标注一个Controller（Class）。在默认情况下，Swagger-Core只会扫描解析具有@Api注解的类，而会自动忽略其他类别资源（JAX-RS endpoints，Servlets等等）的注解。
 *
 *  属性	        描述
 *  value	        url的路径值
 *  tags	        如果设置这个值、value的值会被覆盖
 *  description	    对api资源的描述
 *  basePath	    基本路径可以不配置
 *  position	    如果配置多个Api 想改变显示的顺序位置
 *  produces	    For example, "application/json, application/xml"
 *  consumes	    For example, "application/json, application/xml"
 *  protocols	    Possible values: http, https, ws, wss.
 *  authorizations	高级特性认证时配置
 *  hidden	        配置为true 将在文档中隐藏
 */

@Api(tags = "标准演示接口", description = "提供人员信息相关的 Rest API")
@RestController
@RequestMapping("/api")
public class ApiController {

    /**
     * @Description TODO
     * @Author liuzq
     * @Date 2024/3/15 14:56
     *
     * @ApiOperation 注解在用于对一个操作或HTTP方法进行描述。
     * @ApiParam 作用于请求方法上，定义api参数的注解。
     *
     *
     *    @ApiModelProperty(value = "列表数据",example = "[]")
     *    private List<T> rows; 示例数据会把响应信息覆盖
     *
     */
    @PostMapping("/ps")
    @ApiOperation(value = "接受json参数", notes = "演示json参数是否接受成功")
    public String post(@ApiParam(name = "接收json参数", defaultValue = "{}") @RequestBody String json)  {
        return json;
    }

    // 使用URL query参数
    @ApiOperation(value = "登录接口2", notes = "登录接口的说明2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",//参数名字
                    value = "用户名",//参数的描述
                    required = true,//是否必须传入
                    //paramType定义参数传递类型：有path,query,body,form,header
                    paramType = "query"
            ),
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query")
    })
    @PostMapping(value = "/login2")
    public User login(String username, String password) {
        System.out.println(username + ":" + password);
        User loginForm = new User();
        loginForm.setName(username);
        loginForm.setAge(1);
        return loginForm;
    }



    @PostMapping("/result")
    @ApiOperation(value = "R实体类 泛型<T>", notes = "演示R返回值")
    // 自定义入参
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",  //参数名字
                    value = "用户名",          //参数的描述
                    required = true,          //是否必须传入
                    paramType = "body"        //paramType定义参数传递类型：有path,query,body,form,header
            ),
            @ApiImplicitParam(name = "age", value = "年龄", required = true, paramType = "body")
    })
    public R<User> result(@RequestBody User user) {
        return R.ok(user);
    }



    @PostMapping("/tableDataInfo")
    @ApiOperation(value = "TableDataInfo实体类，泛型List<T>", notes = "演示TableDataInfo返回值")
    public TableDataInfo<User> tableDataInfo(User user){
        TableDataInfo<User> tableDataInfo = new TableDataInfo();
        return tableDataInfo;
    }
}
